package in.ac.dei.edrp.cms.controller.registration.prestagingcontroller;

import in.ac.dei.edrp.cms.constants.CRConstant;
import in.ac.dei.edrp.cms.dao.registration.prestagingdao.ReadyPreStagingDAO;
import in.ac.dei.edrp.cms.daoimpl.activitymaster.StartActivityDaoImpl;
import in.ac.dei.edrp.cms.domain.activitymaster.CountProcessRecorList;
import in.ac.dei.edrp.cms.domain.activitymaster.StartActivityBean;
import in.ac.dei.edrp.cms.domain.registration.prestaging.ActivityMasterBean;
import in.ac.dei.edrp.cms.domain.reportgeneration.ProgressCardInfo;
import in.ac.dei.edrp.cms.domain.utility.ErrorLogs;
import in.ac.dei.edrp.cms.utility.StudentTrackingFunction;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.ibatis.sqlmap.client.SqlMapClient;

public class RegistrationActivityController  extends MultiActionController{
	

private ReadyPreStagingDAO readyPreStagingDAO;
	
public static final Logger logger = Logger.getLogger(RegistrationActivityController.class);

public void setReadyPreStagingDAO(ReadyPreStagingDAO readyPreStagingDAO) {
	System.out.println("Coming here");
	this.readyPreStagingDAO = readyPreStagingDAO;
}


public ModelAndView getProgramActivity(HttpServletRequest request,
		HttpServletResponse response)throws Exception {
	System.out.println("Coming inside getActivity in RegistrationActivity");
	HttpSession session=request.getSession(true);
	
	String universityId=(String)session.getAttribute("universityId");
	String userId=(String)session.getAttribute("userId");
	//System.out.println("Coming in process");
	ActivityMasterBean activityMasterBean=new ActivityMasterBean();
	activityMasterBean.setUniversityId(universityId);
	
	//Since code for process master is attached, so process id will be in list
	System.out.println("Coming here before list");
	List<ActivityMasterBean> activityList = readyPreStagingDAO.getAllActivities(activityMasterBean);
	System.out.println("Coming here after activityList");
//	for(StartActivityBean sta:processList){
//	System.out.println("Coming here"+sta.getComponentDescription());
//	}
	System.out.println("Coming inside 123 activity"+activityList);
	return new ModelAndView("prestaging/ProgramActivity","activityList",activityList);
}

public ModelAndView getSemesterDate(HttpServletRequest request,
		HttpServletResponse response)throws Exception {
	HttpSession session=request.getSession(true);
	
	String universityId=(String)session.getAttribute("universityId");
	String userId=(String)session.getAttribute("userId");
	System.out.println("Coming in getSemesterDate");
	ProgressCardInfo progressCardInfo=new ProgressCardInfo();
	progressCardInfo.setUniversityCode(universityId);
	progressCardInfo.setProgramId((String)request.getParameter("programId"));
	progressCardInfo.setSemesterId((String)request.getParameter("semesterCode"));
	
	
//	progressCardInfo.setSessionStartDate("2011-07-01");
//	progressCardInfo.setSessionEndDate("2012-06-30");
	
	//Since code for process master is attached, so process id will be in list
	ProgressCardInfo semesterDate = readyPreStagingDAO.getSemesterDates(progressCardInfo);
//	for(StartActivityBean sta:processList){
//	System.out.println("Coming here"+sta.getComponentDescription());
//	}
	System.out.println("Coming inside semester dates"+semesterDate);
	return new ModelAndView("reportgeneration/semesterDate","semesterDate",semesterDate);
}

public ModelAndView startActivity(HttpServletRequest request,
		HttpServletResponse response)throws Exception {
	HttpSession session=request.getSession(true);
	
	String universityId=(String)session.getAttribute("universityId");
	String userId=(String)session.getAttribute("userId");
	System.out.println("Coming in process");
	String entityId=request.getParameter("entityId");
	String programId=request.getParameter("programId");
	String semesterCode=request.getParameter("semesterCode");
	String semesterStartDate=request.getParameter("semesterStartDate");
	String semesterEndDate=request.getParameter("semesterEndDate");
	String activityId=request.getParameter("activityId");
	
	System.out.println("Coming inside start activity"+entityId+programId+semesterCode+semesterStartDate+semesterEndDate+activityId);
	ActivityMasterBean activityMasterBean=new ActivityMasterBean();
	activityMasterBean.setUniversityId(universityId);
	activityMasterBean.setEntityId(entityId);
	activityMasterBean.setProgramId(programId);
	activityMasterBean.setSemesterCode(semesterCode);
	activityMasterBean.setSemesterStartDate(semesterStartDate);
	activityMasterBean.setSemesterEndDate(semesterEndDate);
	activityMasterBean.setUserId(userId);
	activityMasterBean.setActivityId(activityId);
	CountProcessRecorList countList=new CountProcessRecorList(0,0,0,0,false);	
	
	try{
		
	if(activityId.equalsIgnoreCase(CRConstant.PRESTAGING_READY_PROCESS)){
	countList=readyPreStagingDAO.makePreStageReady(activityMasterBean);	
	}
	
	if(activityId.equalsIgnoreCase(CRConstant.STAGING_TRANSFER_PROCESS)){
	countList=readyPreStagingDAO.transferRDYinST(activityMasterBean);
	}
	
	}catch(Exception e){
		
	}
	finally{
		
		countList=new CountProcessRecorList(countList.getTotalRecords(),countList.getCorrectProcessed(),countList.getRejectedProcessed(),countList.getInError(),countList.isActivityCompleted());
	}
	return new ModelAndView("activitymaster/CountProcessedRecord", "countList",countList);
}

}
